Method: Integer#<=>

Defined in:
numeric.c

#<=>(other) ⇒ -1, ...

Returns:

  • -1, if self is less than other.

  • 0, if self is equal to other.

  • 1, if self is greater then other.

  • nil, if self and other are incomparable.

Examples:

1 <=> 2              # => -1
1 <=> 1              # => 0
1 <=> 0              # => 1
1 <=> 'foo'          # => nil

1 <=> 1.0            # => 0
1 <=> Rational(1, 1) # => 0
1 <=> Complex(1, 0)  # => 0

This method is the basis for comparisons in module Comparable.

Returns:



4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
# File 'numeric.c', line 4759

VALUE
rb_int_cmp(VALUE x, VALUE y)
{
    if (FIXNUM_P(x)) {
        return fix_cmp(x, y);
    }
    else if (RB_BIGNUM_TYPE_P(x)) {
        return rb_big_cmp(x, y);
    }
    else {
        rb_raise(rb_eNotImpError, "need to define '<=>' in %s", rb_obj_classname(x));
    }
}